<%@ page import="cn.tedu.oa.common.util.ShiroUtils" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台管理</title>
    <link rel="icon" href="${pageContext.request.contextPath}/lib/static/login/images/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/lib/static/common/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <form class="layui-form" lay-filter="test2">
            <div class="layui-logo">思远OA</div>
            <div id="firstMenuDiv">
                <!-- 头部区域（可配合layui已有的水平导航） -->
                <!--
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">需要增加的模块</a></dd>
                </dl>
            </li>
        </ul>-->
            </div>
        </form>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="${pageContext.request.contextPath}/lib/static/common/img/head.jpg" class="layui-nav-img">
                    <%=ShiroUtils.getPrincipal().getUsername()%>
                </a>
                <dl class="layui-nav-child">
                    <dd><a id="showInfo" lay-event="show">基本资料</a></dd>
                    <dd><a id="securitySettings">修改密码</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/logout">注销</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree">
                <li class="layui-nav-item"><a href="">工作台</a></li>
            </ul>
            <span id="leftFirstMenuDiv">
            </span>
        </div>
    </div>

    <div class="layui-body" id="LAY_app_body">
        <div class="layadmin-tabsbody-item layui-show">
            <iframe src="${pageContext.request.contextPath}/main" frameborder="0" width="100%" class="layadmin-iframe" id="iframe" name="right"></iframe>
        </div>
    </div>

    <!-- 底部固定区域 -->
    <div class="layui-footer">
        <div class="layui-col-md8 layui-col-md-offset4">
            Copyright © 2018 思远OA All Rights Reserved. 京ICP证1000001号
        </div>
    </div>
</div>
<script>

    function doSetFirstMenusUl(menuData){
        //1.获取对象，并清空内容
        var div=$("#firstMenuDiv")
        //2.迭代内容将数据追加到对象中<li class="layui-nav-item"><a href="">考勤管理</a></li>
        var meunUl=$("<ul class='layui-nav layui-layout-left'></ul>");
        for(var i=0;i<menuData.length;i++){
            meunUl.append("<li class='layui-nav-item'><a class='clickA' id='"+i+"'>"+menuData[i].name+"</a></li>");
        }
        div.append(meunUl);
        div.data("menuData",menuData);
        $("#firstMenuDiv").on("click",".clickA",doGetLeftFirstMenus)
        return false;
    }
    /*<li class="layui-nav-item layui-nav-itemed">
        <a class="" href="javascript:;">系统管理</a>
            <div>*/
    //<li class='layui-nav-item layui-nav-itemed'><a href='javascript:;'>1111</a></li>
    function doGetLeftFirstMenus(){
        var menuData=$("#firstMenuDiv").data("menuData");
        var data=menuData[$(this).context.id];
        var div=$("#leftFirstMenuDiv");
        div.empty();
        div.append("<ul class='layui-nav layui-nav-tree'><li class='layui-nav-item  layui-nav-itemed'><a id='menu'>"+data.name+"</a><dl class='layui-nav-child' id='menuDl'></dl></li></ul>");
        var menuDl=$("#menuDl");
        var params=data.id.valueOf();
        $.ajax({
            url:"${pageContext.request.contextPath}/sys/menu/getMenusByUser",
            data:{"previousMenuId":params},
            type:"post",
            dataType:"json",
            success:function (result) {
                if(result.code==0){
                    var chilldMenu=result.data;
                    for(var i in chilldMenu){
                        menuDl.append("<dd><a href='${pageContext.request.contextPath}/"+chilldMenu[i].url+"' target='right'>"+chilldMenu[i].name+"</a></dd>")
                    }
                }
            }
        })

        layui.use('element', function () {
            var element = layui.element;
            element.init()
            return false;
        });
    }


    $(function ($) {
        $.ajax({
            url:"${pageContext.request.contextPath}/sys/menu/getFirstMenus",
            type:"post",
            dataType:"json",
            success:function (result) {
                if(result.code==0){
                    var data=result.data;
                    doSetFirstMenusUl(data);
                }

            }
        })

        layui.use(['jquery','element','form'], function () {
            var form=layui.form;
            var element = layui.element
            form.render(null,'test2');
            element.init()
        });

        $("#showInfo").click(function () {
            layer.open({
                content: "${pageContext.request.contextPath}/sys/user/information",
                type: 2,
                title: '<h2>' + '基本资料' + '</h2>',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                offset: '50px',
                area: ['800px', '530px'],
                closeBtn: 2,
                btn: ['关闭']
            });
        });
        $("#securitySettings").click(function () {
            layer.open({
                content: "${pageContext.request.contextPath}/sys/user/security_settings",
                type: 2,
                title: '<h2>' + '安全设置' + '</h2>',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                offset: '50px',
                area: ['600px', '330px'],
                closeBtn: 2,
            });
        });
        /*设置iframe高度为主体内容高度-10*/
        $("#iframe").height($("#LAY_app_body").height() - 10);
    });
</script>
</body>
</html>